package com.tiancheng.trade.settlement.util;

import java.util.Calendar;
import java.util.Iterator;
import java.util.Map;

/**
 * 拼装招商银行sign参数
 */
public class CmbParaUtils {

    /**
     * 获取sign字符串
     *
     * @param map
     * @return
     */
    public static String getSignStr(Map map) {
        Object val = null;
        String key = "";
        Iterator iter = map.entrySet().iterator();
        StringBuilder str = new StringBuilder();
        String res = "";
        while (iter.hasNext()) {
            Map.Entry entry = (Map.Entry) iter.next();
            // 获取key
            key = (String) entry.getKey();
            // 获取value
            val = entry.getValue();
            if (null != val) {
                str.append(key).append("=").append(val).append("&");
            }
        }
        if (str.length() > 0) {
            res = str.toString().substring(0, str.toString().length() - 1);
        }
        return res;
    }

    /**
     * unix时间戳，精确到秒
     *
     * @return
     */
    public static String getTimeStr() {
        Calendar cal = Calendar.getInstance();
        return String.valueOf(cal.getTimeInMillis() / 1000);
    }

}
